import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Search from '../views/Search.vue'
import Menu from '../components/Menu'
import Login from '../views/Login.vue'
import store from "../store"
import Reigist from "../views/Register.vue"
import Submits from "../views/Submits.vue"
Vue.use(VueRouter)

export const routes = [{
        path: '/',
        name: 'Home',
        til: "首页",
        icon: "el-icon-s-home",
        components: {
            default: Home,
            menu: Menu,
        },
        meta: {
            til: "首页",
            isShow: true
        }
    },

    {
        path: '/classify',
        name: 'Classify',
        til: "分类",
        icon: "el-icon-menu",
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        components: {
            default: () =>
                import ('../views/Classify.vue'),
            menu: Menu
        },
        meta: {
            til: "分类",
            isShow: true
        }
    },
    {
        path: '/shopcar',
        name: 'Shopcar',
        til: "购物车",
        icon: "el-icon-shopping-cart-full",
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        components: {
            default: () =>
                import ( /* webpackChunkName: "about" */ '../views/Shopcar.vue'),
            menu: Menu
        },
        meta: {
            til: "购物车",
            isShow: true
        }
    },
    {
        path: '/my',
        name: 'My',
        til: "我的",
        icon: "el-icon-user-solid",
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        components: {
            default: () =>
                import ( /* webpackChunkName: "about" */ '../views/My.vue'),
            menu: Menu
        },
        meta: {
            til: "我的",
            isShow: true
        }
    },


]

const router = new VueRouter({

        mode: 'history',

        routes: [...routes,

            {
                path: '/account',
                name: 'Account',
                component: () =>
                    import ('../views/my/Account.vue'),
                meta: {
                    til: "我的账户"
                }
            },
            {
                path: '/collect',
                name: 'Collect',
                component: () =>
                    import ('../views/my/Collect.vue'),

                meta: {
                    til: "收藏"
                }
            },
            {
                path: '/message',
                name: 'Message',
                component: () =>
                    import ('../views/my/Message.vue'),
                meta: {
                    til: "收货人信息"
                }
            },
            {
                path: '/more',
                name: 'More',
                component: () =>
                    import ('../views/my/More.vue'),
                meta: {
                    til: "更多"
                }
            },
            {
                path: '/search',
                name: 'Search',
                til: "搜索",
                // route level code-splitting
                // this generates a separate chunk (about.[hash].js) for this route
                // which is lazy-loaded when the route is visited.
                components: {
                    default: Search,
                    menu: Menu
                },
                meta: {
                    til: "搜索",

                }
            },
            {
                path: '/list',
                name: 'List',
                // route level code-splitting
                // this generates a separate chunk (about.[hash].js) for this route
                // which is lazy-loaded when the route is visited.
                component: () =>
                    import ( /* webpackChunkName: "about" */ '../views/List.vue'),
                meta: {
                    til: "列表"
                }
            },

            {
                path: '/darticu/:id',
                name: 'Darticu',
                // route level code-splitting
                // this generates a separate chunk (about.[hash].js) for this route
                // which is lazy-loaded when the route is visited.
                component: () =>
                    import ( /* webpackChunkName: "about" */ '../views/Darticu.vue'),
                meta: {
                    til: "详情"
                }
            },

            {
                path: '/details/:id',
                name: 'Details',
                // route level code-splitting
                // this generates a separate chunk (about.[hash].js) for this route
                // which is lazy-loaded when the route is visited.
                component: () =>
                    import ( /* webpackChunkName: "about" */ '../views/Details.vue'),
                meta: {
                    til: "加入学习"
                }
            },
            {
                path: '/login',
                name: 'Login',
                // route level code-splitting
                // this generates a separate chunk (about.[hash].js) for this route
                // which is lazy-loaded when the route is visited.
                components: {
                    default: Login,
                    menu: Menu,
                    meta: {
                        til: "登录"
                    }
                }

            },


            {
                path: '/reigist',
                name: 'Reigist',
                component: Reigist
                    // path: '/reigist',
                    // name: 'Register',
                    // component: () =>
                    //     import ('../views/Register.vue'),
                    // meta: {
                    //     til: "注册"
                    // }
            },
            {
                path: '/orderList',
                name: 'OrderList',
                component: () =>
                    import ('../views/OrderList.vue'),
                children: [{
                        path: '/payment',
                        name: 'Payment',
                        component: () =>
                            import ('../views/my_indent/Payment.vue'),
                        meta: {
                            til: "全部"
                        }
                    },
                    {
                        path: '/after_payment',
                        name: 'After_payment',
                        component: () =>
                            import ('../views/my_indent/After_payment.vue'),
                        meta: {
                            til: "已付款"
                        }
                    },
                    {
                        path: '/appraise',
                        name: 'Appraise',
                        component: () =>
                            import ('../views/my_indent/Appraise.vue'),
                        meta: {
                            til: "待评价"
                        }
                    }
                ],
                meta: {
                    til: "订单"
                }
            },
            {
                path: '/submit',
                name: 'Submit',
                component: () =>
                    import ('../views/Submit.vue'),
                meta: {
                    til: "提交订单"
                }
            },
            {
                path: '/submits',
                name: 'Submits',
                component: () =>
                    import ('../views/Submits.vue'),
                meta: {
                    til: "提交订单"
                }
            },
            {
                path: '/addressList',
                name: 'AddressList',
                component: () =>
                    import ('../views/AddressList.vue'),
                meta: {
                    til: "地址"
                }
            },
            {
                path: '/contactList',
                name: 'ContactList',
                component: () =>
                    import ('../views/ContactList.vue'),
                meta: {
                    til: "联系人"
                }
            },
            {
                path: '/gopay',
                name: 'goPay',
                component: () =>
                    import ('../views/my_indent/goPay.vue'),
                meta: {
                    til: "去支付"
                }
            },
            {
                path: '/goappraise',
                name: 'goAppraise',
                component: () =>
                    import ('../views/my_indent/goAppraise.vue'),
                meta: {
                    til: "去评价"
                }
            },
        ],
        base: process.env.BASE_URL,


    })
    //登陆验证
    // router.beforeEach((to,from,next)=>{
    //     document.title = to.meta.title;

//    // 通过user_id
//    let user_id = store.state.user.user_id;
//    console.log(user_id)
//    // 
//    if(user_id){
//      if(to.path==="/login"){
//        next("/")
//      }else{
//        next() 
//      }
//    }else{
//      //未登录 
//      if(to.path=="/login"){
//        next()
//      }else{
//        next("/login")
//      }

//    }

//  })

export default router